/*
 * @Author: lmk
 * @Date: 2020-11-09 17:20:16
 * @LastEditTime: 2021-11-18 16:38:51
 * @LastEditors: lmk
 * @Description: 
 */
import {
	getList
} from '@/api/crud.js'
const app = {
	state: {
		scene: null,
		categoryList: [],
		busNotice: '',
		completeCar: false,
		cancelCar: false,
		hrefFlag: true,
		currentTheme: 'light', //暗黑模式和白天模式 light
		failLogin: false, //控制登录过期只弹出一次提示框
		lastLook: null, // 记录最近一次打开应用的时间
		redNotif: {
			squareMessage: false, // 广场通知
			issueOrderComment: false, // 发行订单评价
			issueOrder: false, // 发行订单
			issueIncome: false, // 发行收益统计
			issueAfterSale: false, // 发行订单售后
			issueUserIntention: false, // 发行用户意向
			issueExhibitProductComment: false, // 发行展会剧本评测
			storeAfterSale: false, // 店家售后
			storeGatherGame: false, // 店家组局订单
			storeFansGroup: false, // 店家粉丝团
			issueFansGroup: false, // 发行粉丝团
			dmFansGroup: false // dm粉丝团
		}, //红点提示map对象

	},
	mutations: {
		SET_SCENE: (state, scene) => {
			state.scene = scene;
		},
		SET_CATEGORY: (state, categoryList) => {
			state.categoryList = categoryList;
		},
		SET_BUSNOTICE: (state, busNotice) => {
			state.busNotice = busNotice;
		},
		SET_COMPLETECAR: (state, completeCar) => {
			state.completeCar = completeCar;
		},
		SET_CANCELCAR: (state, cancelCar) => {
			state.cancelCar = cancelCar;
		},
		SET_HREFFLAG: (state, flag) => {
			state.hrefFlag = flag;
		},
		SET_FAILLOGIN: (state, flag) => {
			state.failLogin = flag;
		},
		SET_CURRENTTHEME: (state, theme) => {
			state.currentTheme = theme;
		},
		SET_LASTLOOK: (state, time) => {
			state.lastLook = time;
		},
		SET_REDNOTIF: (state, redNotif) => {
			state.redNotif = redNotif;
		},
	},
	actions: {
		scene({
			commit
		}, scene) {
			commit('SET_SCENE', scene)
		},
		//获取平台动态分类
		async getClassify({
			commit,
			state
		}) {
			try {
				if (state.categoryList.length == 0) {
					const res = await getList({
						showLoading: true
					}, 'category', 'shopApi', 'thirdQuery')
					commit('SET_CATEGORY', res)
				}
				return Promise.resolve(state.categoryList)
			} catch (e) {
				return Promise.reject()
				//TODO handle the exception
			}
		},
		//设置上车通知
		busNotice({
			commit
		}, data) {
			commit('SET_BUSNOTICE', data)
			return Promise.resolve()
		},
		//设置结束测本通知
		completeCar({
			commit
		}, completeCar) {
			commit('SET_COMPLETECAR', completeCar)
			return Promise.resolve()
		},
		//取消发车
		cancelCar({
			commit
		}, cancelCar) {
			commit('SET_CANCELCAR', cancelCar)
			return Promise.resolve()
		},
		setHrefFlag({
			commit
		}, flag) {
			commit('SET_HREFFLAG', flag)
			return Promise.resolve()
		},
		setFailLogin({
			commit
		}, flag) {
			commit('SET_FAILLOGIN', flag)
			return Promise.resolve()
		},
		setCurrentTheme({
			commit
		}, theme) {
			commit('SET_CURRENTTHEME', theme)
		},
		setLastLook({
			commit
		}, time) {
			commit('SET_LASTLOOK', time)
		},
		setRedNotif({
			commit,getters
		}, notif) {
			commit('SET_REDNOTIF', notif)
			uni.setStorageSync(`${getters.loginForm.hxUsername}notif`,notif)
		}
	}
}

export default app
